home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks '96 / Talking Telnet / source / main / menuseg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  46.2 KB  |  1,718 lines  |  [TEXT/CWIE]

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1992,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. *****************************************************************
  13. *
  14. *    Menu Handling and initialization code.
  15. *
  16. *    
  17. *    Revisions:
  18. *    7/92 Telnet 2.6 initial version: reorganized defines, put all stray globals in a struct, and
  19. *                put all cursors in a nice array.  Moved some routines to other places -    Scott Bulmahn            
  20. *
  21. *    6/94 Added support for Keypad and Function menus - Carl Bell (Baylor U.)
  22. */
  23.  
  24. #ifdef MPW
  25. #pragma segment 4
  26. #endif
  27.  
  28.  
  29. #include "wind.h"
  30. #include "menuseg.proto.h"
  31. #include "mainseg.proto.h"
  32. #include "Sets.proto.h"                /* JMB: For Saved Sets functions */
  33. #include "configure.proto.h"
  34. #include "parse.proto.h"
  35. #include "InternalEvents.h"
  36. #include "mydnr.proto.h"
  37. #include "rsinterf.proto.h"
  38. #include "network.proto.h"
  39. #include "maclook.proto.h"
  40. #include "vrrgmac.proto.h"
  41. #include "rgmp.proto.h"
  42. #include "tekrgmac.proto.h"
  43. #include "vgtek.proto.h"
  44. #include "netevent.proto.h"
  45. #include "Connections.proto.h"
  46. #include "tnae.h"
  47. #include "authencrypt.proto.h"
  48. #include "vsdata.h"
  49. #include "vsinterf.proto.h"
  50.  
  51. #include "event.proto.h"
  52. #include "macros.proto.h"
  53. #include "DlogUtils.proto.h"            /* For VersionNumber, OutlineItem, and DialogProc Protos */
  54. #include "telneterrors.h"
  55.  
  56.  
  57. #include <Printing.h>
  58. #include "printing.proto.h"
  59. #include "menuseg.proto.h"
  60. #include "translate.proto.h"
  61. #include "parse.proto.h"                // For SendNAWSinfo proto
  62. #include "keypadmenus.proto.h"
  63. #include "LinkedList.proto.h"
  64. #include "speech.proto.h"
  65.  
  66. MenuHandle
  67.     myMenus[NMENUS];        /* Menu Handles .... */
  68. static short lastMenyCommandKeys = -1; //whether last menu set had command keys
  69.  
  70. //char *tempspot;                /* temporary storage ~255 bytes malloc-ed */
  71.  
  72.  
  73. /*
  74.  * External variable declarations (those which we borrow )
  75.  *
  76.  */
  77. extern short scrn;
  78. extern Cursor *theCursors[];
  79. extern WindRec
  80.     *screens,            /* The screen array from Maclook */
  81.     *ftplog;                    /* The FTP log screen from Maclook */
  82. extern    short    nNational;
  83.  
  84. void CloseCaptureFile(short w)
  85. {
  86.     VSclosecapture(w);                                /* BYU 2.4.18 */
  87.     CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  88. }
  89.  
  90. /*    portsOpen()    - Count the number of ports open. Returns 3 different answers
  91.  *                  0= no ports at all, 1= at least active, -1= ports/none active. */
  92. short    portsOpen(void)
  93. {
  94.     short pnum;
  95.  
  96.     pnum=TelInfo->numwindows-1;
  97.     if (pnum<0)  return(0);
  98.     while (pnum>=0) 
  99. //        if (!screens[pnum--].active && !screens[pnum+1].corpse) return(1);
  100.         // corpse status now part of active flag
  101.         if (screens[pnum--].active == CNXN_ACTIVE) return(1);
  102.     return(-1);
  103. }
  104.  
  105. void switchToOptionMenus(Boolean useOptionedStuff)
  106. {
  107.      Str255 theMenuItem;
  108.      short whichString;
  109.      if (useOptionedStuff)
  110.          whichString = CLOSE_ALL_MENU_ITEM;
  111.      else
  112.          whichString = CLOSE_MENU_ITEM;
  113.     
  114.      GetIndString(theMenuItem,MISC_STRINGS,whichString);
  115.     
  116.      SetItem(myMenus[Fil],FLclose,theMenuItem);
  117. }
  118.  
  119. void switchToShiftMenus(Boolean useShiftStuff)
  120. {
  121.      Str255 theMenuItem;
  122.      short whichString;
  123.      if (useShiftStuff)
  124.          whichString = PREVIOUS_SESSION_STRING;
  125.      else
  126.          whichString = NEXT_SESSION_STRING;
  127.     
  128.      GetIndString(theMenuItem,MISC_STRINGS,whichString);
  129.      SetItem(myMenus[Conn],COnext,theMenuItem);
  130.          
  131. }
  132. void    AdjustMenus(void)
  133. {
  134.     short        i;
  135.     WindowPtr    wind;
  136.     
  137.     if ((wind = FrontWindow()) != NULL && (((WindowPeek)wind)->windowKind >= userKind))
  138.         EnableItem( myMenus[Fil],FLclose);
  139.     else
  140.         DisableItem( myMenus[Fil],FLclose);
  141.         
  142.     if ((i=portsOpen()) <1) {
  143.         DisableItem( myMenus[Fil],FLsave);
  144.         DisableItem( myMenus[Fil],FLprint);
  145.         DisableItem( myMenus[Edit],EDcut);
  146.         DisableItem( myMenus[Edit],EDundo);
  147.         DisableItem( myMenus[Edit],EDclear);
  148.         DisableItem( myMenus[Edit],EDcopy);
  149.         DisableItem( myMenus[Edit],EDcopyt);
  150.  
  151.  
  152.         DisableItem( myMenus[Emul],EMbs);
  153.         DisableItem( myMenus[Emul],EMdel);
  154.         DisableItem( myMenus[Emul],EMecho);
  155.         DisableItem( myMenus[Emul],EMwrap);
  156.         DisableItem( myMenus[Emul],EMscroll);
  157.         DisableItem( myMenus[Emul],EMreset);
  158.         DisableItem ( myMenus[Emul],EMjump);
  159.         DisableItem ( myMenus[Emul],EMpage);
  160.         DisableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  161.         DisableItem ( myMenus[Emul],EMscreensize);
  162.         DisableItem ( myMenus[Emul],EMsetup);
  163.         DisableItem ( myMenus[Emul],EMfont);
  164.         DisableItem ( myMenus[Emul],EMsize);
  165.         DisableItem ( myMenus[Emul],EMcolor);
  166.         DisableItem ( myMenus[Emul],EMAnsiColor);
  167.         DisableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  168.  
  169.         DisableItem( myMenus[Net ],NEftp);
  170.         DisableItem( myMenus[Net ],NEip);
  171.         DisableItem( myMenus[Net ],NEayt);
  172.         DisableItem( myMenus[Net ],NEao);
  173.         DisableItem( myMenus[Net ],NEinter);
  174.         DisableItem( myMenus[Net ],NEec);
  175.         DisableItem( myMenus[Net ],NEel);
  176.         DisableItem( myMenus[Net ],NEscroll);
  177.  
  178.         if (TelInfo->ScrlLock) {
  179.             TelInfo->ScrlLock=0;
  180.             CheckItem(myMenus[Net ], NEscroll,FALSE);
  181.             }
  182.         }
  183.     else {
  184.         EnableItem ( myMenus[Fil],FLsave);
  185.         EnableItem ( myMenus[Emul],EMbs);
  186.         EnableItem ( myMenus[Emul],EMdel);
  187.         EnableItem ( myMenus[Emul],EMecho);
  188.         EnableItem ( myMenus[Emul],EMwrap);
  189.         if (nNational > 0) {
  190.             EnableItem ( myMenus[National], 0);
  191.             }
  192.         EnableItem ( myMenus[Emul],EMscroll);
  193.         EnableItem ( myMenus[Emul],EMreset);
  194.         EnableItem ( myMenus[Emul],EMjump);
  195.         EnableItem ( myMenus[Emul],EMpage);
  196.         EnableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  197.         EnableItem ( myMenus[Emul],EMscreensize);
  198.         EnableItem ( myMenus[Emul],EMsetup);
  199.         EnableItem ( myMenus[Emul],EMfont);
  200.         EnableItem ( myMenus[Emul],EMsize);
  201.         EnableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  202.     
  203.         if (TelInfo->haveColorQuickDraw) 
  204.         {
  205.             EnableItem ( myMenus[Emul],EMcolor);
  206.             EnableItem ( myMenus[Emul],EMAnsiColor);
  207.         }
  208.         EnableItem ( myMenus[Net ],NEftp);
  209.         EnableItem ( myMenus[Net ],NEip);
  210.         EnableItem ( myMenus[Net ],NEayt);
  211.         EnableItem ( myMenus[Net ],NEao);
  212.         EnableItem ( myMenus[Net ],NEinter);
  213.         EnableItem ( myMenus[Net ],NEec);
  214.         EnableItem ( myMenus[Net ],NEel);
  215.         EnableItem ( myMenus[Net ],NEscroll);
  216.     }
  217.     
  218. #ifdef    SPEECH
  219.     {
  220.         short    w;
  221.         Boolean    selected;
  222.         
  223.         w = WindowPtr2ScreenIndex(wind);
  224.         selected = 0 <= w ? RSTextSelected(w) : false;
  225.         
  226.         AdjustSpeechMenu(selected);
  227.         
  228.     }
  229. #endif
  230.  
  231. }
  232.  
  233. /*    switchMenus( which) - Switch from our current menus to the key menus (1)
  234.  *                          or the normal menus (0). */
  235. void switchMenus(short which)
  236. {
  237.     short i;
  238.         
  239.     if (lastMenyCommandKeys != which)
  240.     {
  241.         lastMenyCommandKeys = which;
  242.         DeleteMenu( fileMenu);                    /* Take them from the menu bar */
  243.         DeleteMenu( editMenu);
  244.         DeleteMenu( termMenu);
  245.         DeleteMenu(  netMenu);
  246.         DeleteMenu(  keyMenu);                /* Baylor */
  247.         DeleteMenu( funcMenu);                /* Baylor */
  248.         DeleteMenu(NfileMenu);                
  249.         DeleteMenu(NeditMenu);
  250.         DeleteMenu(NtermMenu);
  251.         DeleteMenu(NnetMenu);
  252.  
  253.         if (which) 
  254.         {
  255.             myMenus[Fil ] = GetMenu(NfileMenu);
  256.             myMenus[Edit] = GetMenu(NeditMenu);
  257.             myMenus[Emul] = GetMenu(NtermMenu);
  258.             myMenus[Net ] = GetMenu(NnetMenu );
  259.             myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  260.             myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  261.     
  262.             DelMenuItem(myMenus[Conn],COnext);
  263.             InsMenuItem(myMenus[Conn],(StringPtr)"\017Next Session/N\0",0);
  264.             }
  265.         else 
  266.         {
  267.             myMenus[Fil ] = GetMenu(fileMenu);
  268.             myMenus[Edit] = GetMenu(editMenu);
  269.             myMenus[Emul] = GetMenu(termMenu);
  270.             myMenus[Net ] = GetMenu( netMenu);
  271.             myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  272.             myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  273.     
  274.             DelMenuItem(myMenus[Conn],COnext);
  275.             InsMenuItem(myMenus[Conn],(StringPtr)"\015Next Session\0",0);
  276.         }
  277.     }
  278.     for(i=1; i<Conn; i++)
  279.         InsertMenu( myMenus[i], connMenu);    /* Put them in the menu bar */
  280.  
  281.     if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  282.         InsertMenu(myMenus[Keypad], 0);                        /* Baylor */
  283.         InsertMenu(myMenus[Function], 0);                    /* Baylor */
  284.         }
  285.  
  286.     AdjustMenus();            /* Hilite the right stuff */
  287.  
  288.     if (TelInfo->MacBinary)
  289.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  290.     else
  291.         CheckItem(myMenus[Fil],FLbin,FALSE);
  292.  
  293.     if (TelInfo->ftplogon)
  294.         CheckItem(myMenus[Fil],FLlog,TRUE);        /* and the log .... */
  295.     else
  296.         CheckItem(myMenus[Fil],FLlog,FALSE);
  297.  
  298.     if (TelInfo->ScrlLock)                                 /* and the Suspend network ... */
  299.         CheckItem(myMenus[Net], NEscroll,TRUE);
  300.     else 
  301.         CheckItem(myMenus[Net], NEscroll,FALSE);
  302.  
  303.     if (TelInfo->numwindows>0)                            /* and set the BSDEL flag */
  304.         CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  305.  
  306.     DrawMenuBar();                                /* Draw what we have done */
  307.  
  308.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  309.  
  310.     if (!TelInfo->haveColorQuickDraw)
  311.         DisableItem( myMenus[Emul], EMcolor);
  312.  
  313. }
  314.  
  315. /*    setupmenu - Set up (load) all menus and prepare menu bar.
  316.  *                set default check marks. */
  317. void setupmenu(short def)
  318. {
  319.     lastMenyCommandKeys = def;
  320.     myMenus[0] = GetMenu(appleMenu);                /* Get all of our friendly menus */
  321.     myMenus[Conn] = GetMenu(connMenu);
  322.     myMenus[Font] = GetMenu(fontMenu);
  323.     myMenus[Sizem] = GetMenu(sizeMenu);
  324.     myMenus[OpSpec] = GetMenu(opspecMenu);
  325.     myMenus[PrefsSub] = GetMenu(prefsMenu);
  326.     myMenus[National] = GetMenu(transMenu);
  327.     myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  328.     myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  329.     myMenus[Fil ] = GetMenu(NfileMenu);
  330.     myMenus[Edit] = GetMenu(NeditMenu);
  331.     myMenus[Emul] = GetMenu(NtermMenu);
  332.     myMenus[Net ] = GetMenu(NnetMenu );
  333. #ifdef    SPEECH
  334.     myMenus[Speech] = GetMenu(speechMenu);
  335. #endif    /* SPEECH */
  336.  
  337.     AddResMenu(myMenus[0], 'DRVR');                    /* Add in the DA's */
  338.  
  339.     InsertMenu(myMenus[0], 0);                        /* Insert the Menus into the bar */
  340.     InsertMenu(myMenus[Conn], 0);
  341. #ifdef    SPEECH
  342.     InsertMenu(myMenus[Speech], BuildSpeechMenu(myMenus[Speech]) ? 0 : -1);
  343. #endif    /* SPEECH */
  344.     if (gApplicationPrefs->KeyPadAndFuncMenus) {    /* Baylor */
  345.         InsertMenu(myMenus[Keypad], 0);                /* Baylor */
  346.         InsertMenu(myMenus[Function], 0);            /* Baylor */
  347.         }
  348.     InsertMenu(myMenus[Font], -1);
  349.     InsertMenu(myMenus[Sizem], -1);
  350.     InsertMenu(myMenus[OpSpec], -1);
  351.     InsertMenu(myMenus[National], -1);
  352.     InsertMenu(myMenus[PrefsSub], -1);
  353.     
  354.     addMonoSpacedFonts(myMenus[Font]);
  355.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  356.     switchMenus(def);
  357.  
  358. }
  359.  
  360. void addMonoSpacedFonts(MenuHandle theMenu)
  361. {
  362.     Boolean doItAll = FALSE;
  363.     Handle    theGoodFonts, theBadFonts;
  364.     short    numGoodFonts, numBadFonts,numFontsInMenu;
  365.     short menuIndex;
  366.     Str255 fontListName,currentFontName;
  367.     
  368.     //here begins the caching of fonts to save time caculating proportionality
  369.     UseResFile(TelInfo->SettingsFile);
  370.     
  371.     theGoodFonts = Get1Resource('STR#',4000); //the good fonts
  372.     if (!theGoodFonts)
  373.     {
  374.         UseResFile(TelInfo->ApplicationFile);
  375.         theGoodFonts = Get1Resource('STR#',4000);
  376.         theBadFonts = Get1Resource('STR#',5000);
  377.         DetachResource(theGoodFonts);
  378.         DetachResource(theBadFonts);
  379.         UseResFile(TelInfo->SettingsFile);
  380.         AddResource(theGoodFonts,'STR#',4000,"\pGood Fonts");
  381.         AddResource(theBadFonts,'STR#',5000,"\pBad Fonts");
  382.     }
  383.     else
  384.         theBadFonts = Get1Resource('STR#',5000);
  385.  
  386. redoTheList:            
  387.  
  388.     numGoodFonts = *(short *)(*theGoodFonts);
  389.     if (numGoodFonts == 0)
  390.         doItAll = TRUE; //we haven't created a list of fonts yet
  391.     else
  392.         numBadFonts = *(short *)(*theBadFonts);
  393.  
  394.     AddResMenu(theMenu,'FONT'); //add them all here
  395.     numFontsInMenu = CountMItems(theMenu);
  396.     if (numFontsInMenu != (numBadFonts + numGoodFonts))
  397.     {
  398.         SetHandleSize(theGoodFonts,2);
  399.         *((short *)*theGoodFonts) = 0; 
  400.         SetHandleSize(theBadFonts,2);
  401.         *((short *)*theBadFonts) = 0; 
  402.         doItAll = TRUE;
  403.     }
  404.     if (!doItAll) //we have a list already
  405.     {
  406.         short goodFontIndex, badFontIndex;
  407.         goodFontIndex = badFontIndex = 1;
  408.         
  409.         for (menuIndex = 1; menuIndex <=  numFontsInMenu; menuIndex++)
  410.         {    //look at each font, see if its bad, good, or new
  411.             GetItem(theMenu,menuIndex,currentFontName);
  412.             GetIndString(fontListName,5000,badFontIndex);
  413.             if (EqualString(currentFontName,fontListName,TRUE,FALSE))
  414.             {
  415.                 DelMenuItem(theMenu,menuIndex); //remove the bad font from the menu
  416.                 numFontsInMenu--; 
  417.                 menuIndex--;
  418.                 badFontIndex++;
  419.             }
  420.             else
  421.             {    
  422.                 GetIndString(fontListName,4000,goodFontIndex);
  423.                 if (EqualString(currentFontName,fontListName,TRUE,FALSE))
  424.                     goodFontIndex++;
  425.                 else //its a new font, and we didn't expect it; this means there were an equal
  426.                 {    //number of fonts removed and added.  Lets start over. 
  427.                     short numberInMenu;
  428.                     numberInMenu = CountMItems(theMenu);
  429.                     for (;numberInMenu > 0; numberInMenu--)
  430.                         DelMenuItem(theMenu,numberInMenu);//clear the menu
  431.                     SetHandleSize(theGoodFonts,2);//clear the lists
  432.                     SetHandleSize(theBadFonts,2);
  433.                     
  434.                     goto redoTheList;
  435.                 }
  436.             }
  437.         }
  438.     }        
  439.     else //create a new list
  440.     {
  441.         DialogPtr     dtemp;
  442.         dtemp = GetNewMyDialog(130, NULL, kInFront, (void *)SecondThirdCenterDialog);    /* opening dialog */
  443.         DrawDialog(dtemp);
  444.         
  445.                                             
  446.         for (menuIndex = 1; menuIndex <=  numFontsInMenu; menuIndex++)
  447.         {
  448.             GetItem(theMenu,menuIndex,currentFontName);
  449.             if (!isMonospacedFont(currentFontName))
  450.             {
  451.                 DelMenuItem(theMenu,menuIndex); //remove the bad font from the menu
  452.                 numFontsInMenu--; 
  453.                 menuIndex--;
  454.                 PtrAndHand(currentFontName,theBadFonts,currentFontName[0]+1);//add it to the bad list
  455.                 (*(short *)(*theBadFonts))++;
  456.             }
  457.             else
  458.             {
  459.                 PtrAndHand(currentFontName,theGoodFonts,currentFontName[0]+1);//add it to the good list
  460.                 (*(short *)(*theGoodFonts))++;
  461.             }
  462.         }
  463.         DisposDialog(dtemp);    
  464.     }    
  465.     ChangedResource(theGoodFonts);
  466.     ChangedResource(theBadFonts);
  467.     ReleaseResource(theGoodFonts);
  468.     ReleaseResource(theBadFonts);
  469.     UpdateResFile(TelInfo->SettingsFile);
  470. }
  471.  
  472. Boolean isMonospacedFont(Str255 theFont)
  473. {
  474.     Boolean haveNonRomanScripts,thisOneIsMonospaced = FALSE, doRomanTest = FALSE;
  475.     short fond;
  476.     long tempLong;
  477.     //GrafPtr tempPort, savedPort;
  478.  
  479.     //first, open a temporary port to test CharWidth
  480.     //tempPort = (GrafPtr)myNewPtrCritical(sizeof(GrafPort));
  481.     //GetPort(&savedPort);
  482.     //OpenPort(tempPort);
  483.  
  484.     tempLong = GetScriptManagerVariable(smEnabled);    //this returns number of scripts enable
  485.     haveNonRomanScripts = (tempLong > 1); //if there is one, its roman
  486.     GetFNum(theFont,&fond);
  487.     if (haveNonRomanScripts)
  488.     {
  489.         long thisScriptEnabled;
  490.         ScriptCode scriptNumber;
  491.         
  492.         scriptNumber = FontToScript(fond);
  493.         if (scriptNumber != 0) //if its non-roman
  494.         {
  495.             thisScriptEnabled = GetScriptVariable(scriptNumber,smScriptEnabled);
  496.             if (thisScriptEnabled)
  497.             {
  498.                 //check if this font is the preferred monospaced font for its script
  499.                 long theSizeAndFond;
  500.                 short thePreferredFond;
  501.                 
  502.                 theSizeAndFond = GetScriptVariable(scriptNumber, smScriptMonoFondSize);
  503.                 thePreferredFond = theSizeAndFond >> 16; //high word is fond 
  504.                 thisOneIsMonospaced = (thePreferredFond == fond);
  505.             }
  506.             else
  507.                 thisOneIsMonospaced = FALSE; //this font's script isn't enabled
  508.         }
  509.         else
  510.             doRomanTest = TRUE;
  511.     }
  512.     else
  513.         doRomanTest = TRUE;
  514.         
  515.     if (doRomanTest)
  516.     {
  517.         TextFont(fond);
  518.         thisOneIsMonospaced = (CharWidth('W') == CharWidth('.'));
  519.     }
  520.     //SetPort(savedPort);
  521.     //ClosePort(tempPort);
  522.     //DisposePtr((Ptr)tempPort);
  523.     return(thisOneIsMonospaced);
  524.  
  525. void CheckOpSpecSubmenu(void)
  526. {
  527.     short numItems;
  528.     UseResFile(TelInfo->SettingsFile);
  529.     numItems = Count1Resources(SESSIONPREFS_RESTYPE);
  530.     if (CountMItems(myMenus[OpSpec]) != numItems)
  531.         SetupOpSpecSubmenu(myMenus[OpSpec]);
  532. }
  533.  
  534. void SetupOpSpecSubmenu(MenuHandle theMenu)
  535. {
  536.     short            scratchshort,numberofitems;
  537.     LinkedListNode    *theHead;    
  538.     scratchshort = CountMItems(theMenu);
  539.     for (; scratchshort>0; scratchshort--) DelMenuItem(theMenu, scratchshort);
  540.     
  541.     UseResFile(TelInfo->SettingsFile);
  542.     numberofitems = Count1Resources(SESSIONPREFS_RESTYPE);
  543.     if (numberofitems)
  544.     {    
  545.         theHead = createSortedList(SESSIONPREFS_RESTYPE,numberofitems,"\p<Default>"); //now we have a sorted linked list of the names
  546.         addListToMenu(theMenu,theHead);
  547.         deleteList(&theHead);
  548.     }
  549. }
  550.  
  551. /*    updateMenuChecks() - update the check marks for file transfer
  552.  *                         (MacBinary) */
  553.  
  554. void updateMenuChecks( void)
  555. {
  556.     if (TelInfo->MacBinary)
  557.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  558.     else
  559.         CheckItem(myMenus[Fil],FLbin,FALSE);
  560. }
  561.  
  562. /*    DisplayMacBinary()    - Sets the macbinary check mark according to the MacBinary flag */
  563. void DisplayMacBinary( void)
  564. {
  565.     if (TelInfo->MacBinary)
  566.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  567.     else
  568.         CheckItem(myMenus[Fil],FLbin,FALSE);
  569. }
  570.  
  571. /*CheckFonts()        - Place checkmarks and outlines on the appropriate
  572.  *                          menu items for the fonts */
  573. void CheckFonts(void)
  574. {
  575.     short     i, fsiz, fnum;
  576.     long    itemFontSize;
  577.     Str255     temp, itemString;
  578.  
  579.     RSgetfont( screens[scrn].vs, &fnum, &fsiz);
  580.     GetFontName(fnum, temp);
  581.     
  582.     for(i=1; i<= CountMItems( myMenus[Font]); i++)
  583.         {
  584.         GetItem( myMenus[Font], i, itemString);
  585.         if (EqualString(temp, itemString, FALSE, FALSE))
  586.             CheckItem( myMenus[Font], i, TRUE);            /* Check the current font */
  587.         else
  588.             CheckItem( myMenus[Font], i, FALSE);
  589.         }
  590.     
  591.     for(i=1; i<=CountMItems( myMenus[Sizem]); i++) {
  592.         GetItem( myMenus[Sizem], i, itemString);            /* JMB 2.6 -- Much safer to do it */
  593.         StringToNum(itemString, &itemFontSize);            /*                this way! */
  594.  
  595.         if (fsiz == (short)itemFontSize)
  596.             CheckItem( myMenus[Sizem], i, TRUE);            /* Check Our Current Size */
  597.         else
  598.             CheckItem( myMenus[Sizem], i, FALSE);
  599.  
  600.         if (RealFont( fnum, (short)itemFontSize))        /* Outline All Available REAL Sizes */
  601.             SetItemStyle( myMenus[Sizem], i, outline);
  602.         else
  603.             SetItemStyle( myMenus[Sizem], i, 0);
  604.         }
  605. }
  606.  
  607. /*    applAbout - display the about dialog for the application.*/
  608. void applAbout( void)
  609. {
  610.     DialogPtr About;
  611.     short itemhit;
  612.  
  613.     About=GetNewMyDialog( AboutDLOG, (Ptr) 0L,(WindowPtr) -1L, (void *)ThirdCenterDialog);
  614.     if (About) {
  615.         UItemAssign( About, 2, VersionNumberUPP);
  616.         ModalDialog(NULL, &itemhit);
  617.         DisposDialog(About);
  618.         }
  619. }
  620.  
  621. short ReallyClose( short scrn)
  622. {
  623.     DialogPtr    dtemp;
  624.     short        item;
  625.     Str255        scratchPstring;
  626.     
  627.     SetCursor(theCursors[normcurs]);
  628.  
  629.     GetWTitle(screens[scrn].wind, scratchPstring);
  630.     ParamText(scratchPstring, NULL, NULL, NULL);
  631.     
  632.     dtemp = GetNewMyDialog( CloseDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  633.  
  634.     item = DLOGCancel +1;
  635.     while (item> DLOGCancel)
  636.         ModalDialog(DLOGwOK_CancelUPP, &item);
  637.  
  638.     DisposDialog( dtemp);
  639.  
  640.     updateCursor(1);
  641.     
  642.     if (item == DLOGCancel) return(0);
  643.  
  644.     return(1);
  645. }
  646.  
  647. PicHandle RGtoPICT(short i)
  648. {
  649.     short j;
  650.     PicHandle tpic;
  651.     Rect trect;
  652.  
  653.     SetRect(&trect,0,0,384,384);
  654.     j=VGnewwin(TEK_DEVICE_PICTURE,VGgetVS(i));            /* NCSA 2.5: get the right VS */
  655.     RGMPsize( &trect );
  656.     VGzcpy( i, j);                /* Love dat zm factr */
  657.     tpic=OpenPicture(&trect);
  658.     ClipRect(&trect);
  659.     
  660.     VGredraw(i,j);
  661.     ClosePicture();
  662.     VGclose(j);
  663.  
  664.     return(tpic);
  665. }
  666.  
  667. /* 
  668.  * copyGraph    - Copy the current graphics screen.
  669.  *            dnum - the number of the drawing to copy .
  670.  */
  671. void copyGraph( short dnum)
  672. {
  673.     long tlong;                    /* Temporary Variable */
  674.     PicHandle tpic;                /* Mental picture of the thing */
  675.  
  676.     tpic=RGtoPICT(dnum);            /* Get the picture */
  677.     tlong=ZeroScrap();                /* Nobody else can live here */
  678.     HLock((Handle) tpic);                    /* Lock it for Puting */
  679.     tlong=PutScrap(GetHandleSize((Handle) tpic),'PICT', (Ptr) *tpic);    /* Store as a PICT */
  680.     HUnlock((Handle) tpic);                    /* Unlock so we can toss it */
  681.     KillPicture(tpic);                /* Kill the picture..... */
  682. }                
  683.  
  684. /* 
  685.  * copyText    - Copy the current selection on the virtual screen
  686.  *            vs - the number of the virtual screen to copy from
  687.  */
  688.  
  689. void copyText( short vs)
  690. {
  691.     char **charh;            /* where to store the characters */
  692.     long tlong;                /* Necessary temporary variable */
  693.  
  694.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  695.  
  696.     charh=RSGetTextSel(vs,0);        /* Get the text selection */
  697.  
  698.     if (charh == (char **)-1L)
  699.         OutOfMemory(400);
  700.     else if (charh != (char **)0L) {    /* BYU LSC - Can't do anything without characters */
  701.         HLock(charh);                /* Lock for putting */
  702.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  703.                                     /* Put it as a TEXT resource */
  704.         HUnlock(charh);                /* Unlock for disposal */
  705.         DisposHandle(charh);        /* Kill the chars */
  706.         }
  707. }
  708.  
  709. /* 
  710.  * copyTable   - Copy the current selection on the virtual screen
  711.  *            vs - the number of the virtual screen to copy from
  712.  */
  713.  
  714. void copyTable( short vs)
  715. {
  716.     char **charh;            /* where to store the characters */
  717.     long tlong;                /* Necessary temporary variable */
  718.  
  719.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  720.  
  721.     charh=RSGetTextSel(vs, gApplicationPrefs->CopyTableThresh);        /* Get the text selection */
  722.  
  723.     if (charh>(char **)0L) {                    /* BYU LSC - Can't do anything without characters */
  724.         HLock(charh);                /* Lock for putting */
  725.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  726.                                     /* Put it as a TEXT resource */
  727.         HUnlock(charh);                /* Unlock for disposal */
  728.         DisposHandle(charh);        /* Kill the chars */
  729.         }
  730.     else putln("No characters to copy darn it!");
  731. }
  732.  
  733. /*
  734.  *    paste - Paste the resource from the scrap into the current WIND, if
  735.  *            and only if it is really text
  736.  */
  737.  
  738. void paste( void)
  739. {
  740.     long
  741.         off,                /* offset */
  742.         length;                /* the lenght of what is on the Scrap */
  743.  
  744.     if (screens[scrn].clientflags & PASTE_IN_PROGRESS) {  // One paste at a time, please
  745.         SysBeep(4);
  746.         return;
  747.         }
  748.         
  749.     /* Flush the buffer if necessary */ //CCP fix for linemode
  750.     if (screens[scrn].kblen>0)
  751.     {    
  752.         netpush(screens[scrn].port);
  753.         netwrite( screens[scrn].port, screens[scrn].kbbuf,
  754.                     screens[scrn].kblen);    
  755.         screens[scrn].kblen=0;
  756.     }
  757.  
  758.     if (GetScrap(0L, 'TEXT', &off)<=0L)        /* If there are no TEXT res's */
  759.             return;                        /* then we can't paste it */
  760.  
  761.     screens[scrn].outhand=myNewHandle(0L);    /* create a handle to put chars in */
  762.  
  763.     length= GetScrap( screens[scrn].outhand, 'TEXT',&off);
  764.                                             /* Store the scrap into the handle */
  765.     screens[scrn].outlen = length;            /* Set the length */
  766.     HLock(screens[scrn].outhand);            /* Lock the Handle down for safety */
  767.     screens[scrn].outptr=*screens[scrn].outhand;    /* Set the pointer */
  768.  
  769.     screens[scrn].clientflags |= PASTE_IN_PROGRESS;
  770.     screens[scrn].incount = 0;
  771.     screens[scrn].outcount = 0;
  772.     
  773.     trbuf_mac_nat((unsigned char *)screens[scrn].outptr,screens[scrn].outlen, screens[scrn].national);    /* LU: translate to national chars */
  774.  
  775.     pasteText( scrn);    /* BYU LSC - routine to paste to net, w/echo if neccessary */
  776. }
  777.  
  778. void displayStatus(short n)
  779. {
  780.     DialogPtr        dptr;
  781.     short            item;
  782.     Str255            scratchPstring,anotherString;
  783.     
  784.     SetCursor(theCursors[normcurs]);
  785.     
  786.     switch(screens[n].active) {
  787.         case CNXN_ISCORPSE:
  788.             GetWTitle(screens[n].wind, scratchPstring);
  789.             GetIndString(anotherString,MISC_STRINGS,AWAITING_DISMISSAL_STRING);
  790.             ParamText( scratchPstring, anotherString, NULL, NULL);
  791.             break;
  792.         case CNXN_OPENING:
  793.             GetIndString(anotherString,MISC_STRINGS,BEING_OPENED_STRING);
  794.             ParamText( screens[n].machine,anotherString, NULL, NULL);
  795.             break;
  796.         default:
  797.             GetIndString(anotherString,MISC_STRINGS,BEING_LOOKED_UP);
  798.             ParamText( screens[n].machine,anotherString, NULL, NULL);
  799.         }
  800.  
  801.     dptr = GetNewMyDialog( StatusDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  802.  
  803.     item = DLOGCancel+1;
  804.     while (item > DLOGCancel)
  805.         ModalDialog(DLOGwOK_CancelUPP, &item);
  806.  
  807.     updateCursor(1);
  808.     
  809.     if (item == DLOGCancel) {
  810.         netclose(screens[n].port);
  811.         destroyport( n);
  812.         }    
  813.  
  814.     DisposDialog(dptr);
  815. }
  816.  
  817. /*
  818.  *    changeport - handle the menu updates for changing from one port to another
  819.  */
  820. void changeport(short oldprt, short newprt)
  821. {
  822.  
  823.     //sprintf(tempspot,"oldscrn: %d, newscrn: %d",oldprt,newprt); putln(tempspot);
  824.     
  825.     if (screens[oldprt].active == CNXN_ACTIVE) 
  826.         CheckItem(myMenus[Conn], oldprt + FIRST_CNXN_ITEM, FALSE);        /* Adjust Conn menu */
  827.     CheckItem(myMenus[Conn], newprt + FIRST_CNXN_ITEM, TRUE);
  828.  
  829.     CheckItem(myMenus[Emul], EMbs,FALSE);                        /* Adjust BS */
  830.     CheckItem(myMenus[Emul], EMdel,FALSE);
  831.     CheckItem(myMenus[Emul], EMbs+screens[newprt].bsdel,TRUE);    /* and DEL */
  832.  
  833.     if (screens[newprt].tektype < 0) {    // TEK is inhibited
  834.         DisableItem(myMenus[Emul],EMclear);
  835.         DisableItem(myMenus[Emul],EMpage);
  836.         }
  837.     else {
  838.         EnableItem(myMenus[Emul],EMclear);
  839.         EnableItem(myMenus[Emul],EMpage);
  840.     
  841.         if (screens[newprt].tekclear)                /* BYU 2.4.8 */
  842.             CheckItem(myMenus[Emul],EMclear,TRUE);    /* BYU 2.4.8 */
  843.         else                                         /* BYU 2.4.8 */
  844.             CheckItem(myMenus[Emul],EMclear,FALSE);    /* BYU 2.4.8 */
  845.         }
  846.         
  847.     if (screens[newprt].ESscroll)
  848.         CheckItem(myMenus[Emul],EMscroll,TRUE);
  849.     else 
  850.         CheckItem(myMenus[Emul],EMscroll,FALSE);
  851.  
  852.     if (screens[newprt].echo)                     /* LOCAL ECHO */
  853.         CheckItem(myMenus[Emul],EMecho,TRUE);
  854.     else                                         /* REMOTE ECHO */
  855.         CheckItem(myMenus[Emul],EMecho,FALSE);
  856.         
  857.     if (screens[newprt].wrap)                     /* wrap on */
  858.         CheckItem(myMenus[Emul],EMwrap,TRUE);
  859.     else                                         /* wrap off */
  860.         CheckItem(myMenus[Emul],EMwrap,FALSE);
  861.  
  862.     if (VSiscapturing(screens[newprt].vs))                /* BYU 2.4.18 */
  863.         CheckItem(myMenus[Emul], EMcapture,TRUE);        /* BYU 2.4.18 */
  864.     else                                                /* BYU 2.4.18 */
  865.         CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  866.  
  867.     if (screens[newprt].arrowmap)                        /* JMB */
  868.         CheckItem(myMenus[Emul],EMarrowmap, TRUE);        /* JMB */
  869.     else                                                /* JMB */
  870.         CheckItem(myMenus[Emul],EMarrowmap, FALSE);        /* JMB */
  871.         
  872.     if (screens[newprt].pgupdwn)                        /* JMB */
  873.         CheckItem(myMenus[Emul],EMpgupdwn, TRUE);        /* JMB */
  874.     else                                                /* JMB */
  875.         CheckItem(myMenus[Emul],EMpgupdwn, FALSE);        /* JMB */
  876.     
  877.     scrn=newprt;
  878.  
  879.     CheckFonts();
  880.  
  881.     CheckNational(screens[newprt].national);
  882. }
  883.  
  884. // Returns TRUE if the user cancelled the quit
  885. Boolean    HandleQuit(void)
  886. {
  887.     short    i;
  888.     Boolean liveConnections = FALSE, die = TRUE;
  889.     
  890.     if (TelInfo->numwindows>0) 
  891.     {
  892.         for(i = 0; i < MaxSess; i++)
  893.         {
  894.             if ((screens[i].active == CNXN_ACTIVE)||(screens[i].active == CNXN_OPENING))
  895.                 liveConnections = TRUE;
  896.         }
  897.         if (liveConnections)
  898.             die = AskUserAlert(REALLY_QUIT_QUESTION, FALSE);
  899.         
  900.         if (die) 
  901.         {
  902.             for (i = TelInfo->numwindows - 1; i >= 0; i--) 
  903.             {
  904.                 netclose(screens[i].port);
  905.                 destroyport(i);
  906.             }
  907.         }
  908.         else
  909.             return (TRUE);
  910.      }
  911.     if (gApplicationPrefs->destroyKTickets)
  912.         DestroyTickets();
  913.     quit();
  914.     return (FALSE);
  915. }
  916.  
  917. /*
  918.  *    HandleMenuCommand - preform a command denoted by the arguments.
  919.  *        mResult - the result of the menu event
  920.  *        modifiers- modifiers from the menu event
  921.  */
  922.  
  923. void HandleMenuCommand( long mResult, short modifiers)
  924. {
  925.     register short i;
  926.     short theItem, theMenu;
  927.     Boolean doWrap;
  928.  
  929.     theMenu = mResult >> 16;
  930.     theItem = mResult & 0xffff;
  931.     switch(theMenu) {
  932.     case appleMenu:
  933.         if (theItem==1)                /* About Dialog */
  934.             applAbout();
  935.         else
  936.           {
  937.             Str255
  938.                 name;
  939.             GetItem(myMenus[0], theItem, name);        /* Desk accessory */
  940.             OpenDeskAcc(name);
  941.           }
  942.         break;
  943.  
  944.     case fileMenu:
  945.     case NfileMenu:
  946.         switch(theItem) {            
  947.             
  948.         case FLopen:
  949.             PresentOpenConnectionDialog();                    /* Open a connection */                
  950.             break;
  951.  
  952.         case FLclose:                                    /* Close a connection */
  953.             if (!(modifiers &  optionKey))
  954.                 CloseAWindow(FrontWindow());
  955.             else
  956.             {
  957.                 Boolean die = TRUE;
  958.                 if (numberLiveConnections())
  959.                     die = AskUserAlert(CLOSE_ALL_WINDOWS_Q, FALSE);
  960.                 
  961.                 if (die) 
  962.                 {
  963.                     for (i = TelInfo->numwindows - 1; i >= 0; i--) 
  964.                     {
  965.                         netclose(screens[i].port);
  966.                         destroyport(i);
  967.                     }
  968.                 }
  969.                 else
  970.                     break;
  971.             }
  972.             break;
  973.  
  974.         case FLload:                                /* Load a set */
  975.             LoadSet();
  976.             break;
  977.         case FLsave:                                /* Save a set */
  978.             if (TelInfo->numwindows<1) break;
  979.             SaveSet();
  980.             break;
  981.         case FLbin:                                    /* Toggle MacBinary on/off */
  982.             TelInfo->MacBinary = !TelInfo->MacBinary;
  983.             if (TelInfo->MacBinary) {
  984.                 CheckItem(myMenus[Fil], FLbin,TRUE);
  985.                 }
  986.             else {
  987.                 CheckItem(myMenus[Fil], FLbin,FALSE);
  988.                 }
  989.             break;
  990.  
  991.         case FLlog:                                        /* Toggle FTP window on/off*/
  992.             TelInfo->ftplogon=!TelInfo->ftplogon;
  993.             if(TelInfo->ftplogon) {
  994.                 CheckItem(myMenus[Fil],FLlog,TRUE);
  995.                 RSshow(ftplog->vs);
  996.                 SelectWindow(ftplog->wind);
  997.                 }
  998.             else {
  999.                 CheckItem(myMenus[Fil],FLlog,FALSE);
  1000.                 RShide(ftplog->vs);
  1001.                 }
  1002.             break;
  1003.  
  1004.         case FLprint:                                /* Print Selection (or gr) */
  1005.             PrintSelection();
  1006.             break;
  1007.  
  1008.         case FLpset:                                    /* Set up for printer */
  1009.             PrintPageSetup();
  1010.             break;
  1011.  
  1012.         case FLquit:
  1013.             (void) HandleQuit();
  1014.             break;
  1015.  
  1016.         }
  1017.         break;
  1018.  
  1019.     case editMenu:
  1020.     case NeditMenu:
  1021.         if (!SystemEdit(theItem-1)) {                /* Is this mine? */
  1022.             switch(theItem) {
  1023.             case EDcopy:                            /* Copy */
  1024.                 i = MacRGfindwind(FrontWindow());    /* is ICR window? */
  1025.                 if (i >= 0)
  1026.                     MacRGcopy(FrontWindow());        /* copy the ICR window */
  1027.                 else {
  1028.                     i=RGgetdnum(FrontWindow());
  1029.                     if (i>-1)                        /* Copy Graphics */
  1030.                         copyGraph( i);
  1031.                     else                            /* Copy Text */
  1032.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  1033.                             copyText( i);
  1034.                 }
  1035.                 break;
  1036.  
  1037.             case EDcopyt:                            /* Copy Table */
  1038.                 /* 
  1039.                 *  tech note #180 trick to get MultiFinder to pay attention 
  1040.                 */
  1041.                 if (!SystemEdit(EDcopy-1)) {        /* tell it we did a copy */
  1042.                     i=RGgetdnum(FrontWindow());
  1043.                     if (i>-1)            /* Copy Graphics */
  1044.                         copyGraph( i);
  1045.                     else                /* Copy Text */
  1046.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  1047.                             copyTable( i);
  1048.                 }
  1049.                 break;
  1050.  
  1051.             case EDpaste:                            /* Paste */
  1052.                 if (TelInfo->numwindows<1)
  1053.                         break;
  1054.                     else paste();            /* Paste if there is a wind to do to*/
  1055.                 break;
  1056.             case EDmacros:                            /* Set them Macros */
  1057.                 Macros();
  1058.                 break;
  1059.             default:
  1060.                 break;
  1061.             }
  1062.         }
  1063.         break;
  1064.  
  1065.     case connMenu:
  1066.     case NconnMenu:
  1067.         if (theItem == COnext) 
  1068.         {
  1069.             if (TelInfo->numwindows >1) 
  1070.             {
  1071.                 short    scratchshort;
  1072.                 if (!(modifiers &  shiftKey)) //go forward
  1073.                 {
  1074.                     scratchshort = WindowPtr2ScreenIndex(FrontWindow()) + 1;
  1075.                     // Skip over inactive connections
  1076.                     while(    (screens[scratchshort].active != CNXN_ACTIVE) &&
  1077.                             (screens[scratchshort].active != CNXN_ISCORPSE) &&
  1078.                             (scratchshort <= TelInfo->numwindows+1))                        
  1079.                         scratchshort++;
  1080.                     if ((scratchshort < 0) || (scratchshort >= TelInfo->numwindows))
  1081.                         scratchshort = 0;
  1082.                 }
  1083.                 else //go backward
  1084.                 {
  1085.                     scratchshort = WindowPtr2ScreenIndex(FrontWindow()) - 1;
  1086.                     // Skip over inactive connections
  1087.                     while(    (screens[scratchshort].active != CNXN_ACTIVE) &&
  1088.                             (screens[scratchshort].active != CNXN_ISCORPSE) &&
  1089.                             (scratchshort >= 0))                        
  1090.                         scratchshort--;
  1091.                     if ((scratchshort < 0) || (scratchshort >= TelInfo->numwindows))
  1092.                         scratchshort = TelInfo->numwindows - 1;
  1093.                 }        
  1094.                 SelectWindow(screens[scratchshort].wind);
  1095.             }
  1096.             break;
  1097.         }
  1098.         
  1099.         if (theItem == COtitle)    {
  1100.             ChangeWindowName(FrontWindow());
  1101.             break;
  1102.             }
  1103.             
  1104.         if (theItem >= FIRST_CNXN_ITEM) {
  1105.             if ((theItem - FIRST_CNXN_ITEM-1)>(TelInfo->numwindows+1)) break;  /* rotten danish */
  1106.             if (screens[theItem - FIRST_CNXN_ITEM].active != CNXN_ACTIVE) {
  1107.                 displayStatus(theItem - FIRST_CNXN_ITEM);    /* Tell them about it..... */
  1108.                 break;
  1109.                 }
  1110.             else {
  1111.                 HiliteWindow(screens[scrn].wind, FALSE);
  1112.                 changeport(scrn,(theItem - FIRST_CNXN_ITEM));
  1113.                 if (!(modifiers &  optionKey)) SelectWindow(screens[scrn].wind);
  1114.                 else HiliteWindow(screens[scrn].wind, TRUE);
  1115.                 }
  1116.             }
  1117.         break;
  1118.  
  1119.     case netMenu:
  1120.     case NnetMenu:
  1121.         switch(theItem) {
  1122.         case NEftp:                                        /* Send FTP command */
  1123.         case NEip:                                        /* Send IP Number */
  1124.             if (TelInfo->numwindows<1) break;
  1125.             {    char tmpout[30];                        /* Basically the same except for */
  1126.                 unsigned char tmp[4];                    /* The ftp -n phrase in NEftp */
  1127.  
  1128.                 if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  1129.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1130.                                 screens[scrn].kblen);/* if not empty send buffer */
  1131.                     screens[scrn].kblen=0;
  1132.                     }
  1133.                 netgetip(tmp);
  1134.                 if (theItem == NEftp) {
  1135.                     if ((gFTPServerPrefs->ServerState == 1) && !(modifiers & shiftKey))
  1136.                         sprintf(tmpout,"ftp -n %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);
  1137.                     else
  1138.                         sprintf(tmpout,"ftp %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);
  1139.                     }
  1140.                 else
  1141.                     sprintf(tmpout,"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  1142.                 netwrite(screens[scrn].port,tmpout,strlen(tmpout));
  1143.                 if (screens[scrn].echo)
  1144.                     VSwrite(screens[scrn].vs,tmpout, strlen(tmpout));
  1145.             }
  1146.             break;
  1147.  
  1148.         case NEayt:                                /* Send "Are You There?"*/
  1149.             if (TelInfo->numwindows<1) break;
  1150.             netpush(screens[scrn].port);
  1151.             netwrite(screens[scrn].port, "\377\366",2);
  1152.             break;
  1153.  
  1154.         case NEao:                                /* Send "Abort Output"*/
  1155.             if (TelInfo->numwindows<1) break;
  1156.             netpush(screens[scrn].port);
  1157.             netwrite(screens[scrn].port, "\377\365",2);
  1158.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  1159.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  1160.             break;
  1161.  
  1162.         case NEinter:                                /* Send "Interrupt Process"*/
  1163.             if (TelInfo->numwindows<1) break;
  1164.             netpush(screens[scrn].port);
  1165.             netwrite(screens[scrn].port, "\377\364",2);
  1166.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  1167.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  1168.             break;
  1169.  
  1170.         case NEec:                                /* Send "Erase Character"*/
  1171.             if (TelInfo->numwindows<1) break;
  1172.             netpush(screens[scrn].port);
  1173.             netwrite(screens[scrn].port, "\377\367",2);
  1174.             break;
  1175.  
  1176.         case NEel:                                /* Send "Erase Line"*/
  1177.             if (TelInfo->numwindows<1) break;
  1178.             netpush(screens[scrn].port);
  1179.             netwrite(screens[scrn].port, "\377\370",2);
  1180.             break;
  1181.             
  1182.         case NEscroll:                            /* Suspend Network */
  1183.             TelInfo->ScrlLock=!TelInfo->ScrlLock;
  1184.             if (TelInfo->ScrlLock) 
  1185.                 CheckItem(myMenus[Net], NEscroll,TRUE);
  1186.             else 
  1187.                 CheckItem(myMenus[Net], NEscroll,FALSE);
  1188.             break;
  1189.  
  1190.         case NEnet:                                /* Show Network Numbers */
  1191.             showNetNumbers();
  1192.             break;
  1193.  
  1194.         default:
  1195.             break;
  1196.         }
  1197.         break;
  1198.  
  1199.     case termMenu:
  1200.     case NtermMenu:
  1201.         switch(theItem) {
  1202.  
  1203.         case EMbs:                                /* Backspace for backspace  */
  1204.             if (TelInfo->numwindows<1) break;
  1205.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  1206.             screens[scrn].bsdel=0;
  1207.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,TRUE);
  1208.             break;
  1209.         
  1210.         case EMdel:                                /* Delete for backspace */
  1211.             if (TelInfo->numwindows<1) break;
  1212.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  1213.             screens[scrn].bsdel=1;
  1214.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,TRUE);
  1215.             break;
  1216.  
  1217.         case EMecho:                                /* Toggle Local Echo (if poss.) */
  1218.             if (TelInfo->numwindows < 1) break;
  1219.             if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  1220.                 netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1221.                             screens[scrn].kblen);    /* if not empty send buffer */
  1222.                 screens[scrn].kblen=0;
  1223.                 }
  1224.             screens[scrn].echo= !screens[scrn].echo;    /* toggle */
  1225.             if (screens[scrn].echo) {                    /* LOCAL ECHO */
  1226.                 send_dont(screens[scrn].port,1);
  1227.                 CheckItem(myMenus[Emul],EMecho,TRUE);
  1228.                 }
  1229.             else {                                        /* REMOTE ECHO */
  1230.                 send_do(screens[scrn].port,1);
  1231.                 CheckItem(myMenus[Emul],EMecho,FALSE);
  1232.                 }
  1233.             break;
  1234.             
  1235.         case EMwrap:                                /* wrap mode */
  1236.             if (TelInfo->numwindows < 1) break;
  1237.             if (!screens[scrn].wrap) {                /* is off, turn on */
  1238.                 screens[scrn].wrap = 1;
  1239.                 CheckItem( myMenus[Emul],EMwrap, TRUE);
  1240.                 VSwrite(screens[scrn].vs, "\033[?7h",5);    /* kick emulator */
  1241.                 }
  1242.             else {
  1243.                 screens[scrn].wrap = 0;
  1244.                 CheckItem( myMenus[Emul],EMwrap, FALSE);
  1245.                 VSwrite(screens[scrn].vs, "\033[?7l",5);
  1246.                 }
  1247.             break;
  1248.         
  1249.         case EMarrowmap:                                        /* JMB */
  1250.             if (TelInfo->numwindows < 1) break;                    /* JMB */
  1251.             screens[scrn].arrowmap = !screens[scrn].arrowmap;    /* JMB */
  1252.             if (screens[scrn].arrowmap)                            /* JMB */
  1253.                 CheckItem( myMenus[Emul], EMarrowmap, TRUE);    /* JMB */
  1254.             else                                                /* JMB */
  1255.                 CheckItem( myMenus[Emul], EMarrowmap, FALSE);    /* JMB */
  1256.             break;                                                /* JMB */
  1257.             
  1258.         case EMpgupdwn:
  1259.             if (TelInfo->numwindows < 1) break;                    /* JMB */
  1260.             screens[scrn].pgupdwn = !screens[scrn].pgupdwn;        /* JMB */
  1261.             if (screens[scrn].pgupdwn)                            /* JMB */
  1262.                 CheckItem( myMenus[Emul], EMpgupdwn, TRUE);        /* JMB */
  1263.             else                                                /* JMB */
  1264.                 CheckItem( myMenus[Emul], EMpgupdwn, FALSE);    /* JMB */
  1265.             break;                                                /* JMB */
  1266.             
  1267.         case EMscroll:                                        /* Scrollback on CLS */
  1268.             if (TelInfo->numwindows<1) break;
  1269.             screens[scrn].ESscroll = !screens[scrn].ESscroll;
  1270.             VSscrolcontrol( screens[scrn].vs, -1, screens[scrn].ESscroll);
  1271.             if (screens[scrn].ESscroll)
  1272.                 CheckItem(myMenus[Emul],EMscroll, TRUE);
  1273.             else
  1274.                 CheckItem(myMenus[Emul],EMscroll, FALSE);
  1275.             break;
  1276.             
  1277.         case EMpage:                                    /* TEK page command */
  1278.             if (TelInfo->numwindows<1) break;
  1279.             parse( &screens[scrn],  (unsigned char *) "\033\014",2);    /* BYU LSC */
  1280.             break;
  1281.  
  1282.         case EMclear:                                /* BYU 2.4.8 - Clear on TEK page */
  1283.             if (TelInfo->numwindows<1) break;
  1284.             screens[scrn].tekclear = !screens[scrn].tekclear;
  1285.             if (screens[scrn].tekclear)
  1286.                 CheckItem(myMenus[Emul],EMclear, TRUE);
  1287.             else
  1288.                 CheckItem(myMenus[Emul],EMclear, FALSE);
  1289.             break;
  1290.  
  1291.         case EMscreensize:
  1292.             if (TelInfo->numwindows<1) break;        /* NCSA: SB */
  1293.             SetScreenDimensions((short)scrn);        /* NCSA: SB */
  1294.             break;
  1295.  
  1296.         case EMreset:                                    /* Reset Screen */
  1297.             //RESTORE WRAP AFTER THE RESET!!! BUGG
  1298.             if (TelInfo->numwindows<1) break;
  1299.             doWrap = screens[scrn].wrap;
  1300.             VSreset(screens[scrn].vs);                    /* Reset it */
  1301.             screens[scrn].timing=0;
  1302.             if (doWrap)
  1303.                 VSwrite(screens[scrn].vs, "\033[?7h",5);
  1304.             else
  1305.                 CheckItem( myMenus[Emul],EMwrap, FALSE);
  1306.             break;
  1307.         case EMjump:                                    /* Jump Scroll */
  1308.             if (TelInfo->numwindows<1) break;
  1309.             FlushNetwork(scrn);                            /* Flush it */
  1310.             break;
  1311.             
  1312.         case EMsetup:                            /* need dialog to enter new key values */
  1313.             setupkeys();
  1314.             break;
  1315.  
  1316.         case EMcolor:                                        /* Set color */
  1317.             if (TelInfo->numwindows<1) break;
  1318.             if (TelInfo->haveColorQuickDraw)
  1319.                 RScprompt(screens[scrn].vs);    
  1320.             break;
  1321.         case EMAnsiColor:
  1322.             if (TelInfo->haveColorQuickDraw)
  1323.                 AnsiPrompt();
  1324.                 RSUpdatePalette();
  1325.             return;    
  1326.         case EMcapture:                                            /* BYU 2.4.18 - Capture session to file */
  1327.             if (VSiscapturing(screens[scrn].vs)) {                /* BYU 2.4.18 */
  1328.                 CloseCaptureFile(screens[scrn].vs);                /* BYU 2.4.18 */
  1329.             } else {                                            /* BYU 2.4.18 */
  1330.                 if(VSopencapture(scrn, screens[scrn].vs))        /* BYU 2.4.18 */
  1331.                     CheckItem(myMenus[Emul], EMcapture,TRUE);    /* BYU 2.4.18 */
  1332.             }                                                    /* BYU 2.4.18 */
  1333.  
  1334.             break;                                                /* BYU 2.4.18 */
  1335. #define    SPEECH
  1336. #ifdef    SPEECH
  1337.         case EMspeaking:
  1338.             AnnoyingSpeechMode(screens[scrn].vs);
  1339.             break;
  1340. #endif
  1341.  
  1342.         default:
  1343.             break;
  1344.         }
  1345.         break;
  1346.     case fontMenu:
  1347.         if (TelInfo->numwindows>0) {
  1348.             short     itemFontNum;
  1349.             Str255     temp;
  1350.             
  1351.             GetItem( myMenus[Font], theItem, temp);
  1352.             GetFNum( temp, &itemFontNum);
  1353.             
  1354.             RSchangefont( screens[scrn].vs, itemFontNum, 0);
  1355.             CheckFonts();
  1356.             }
  1357.         break;
  1358.     case sizeMenu:
  1359.         if (TelInfo->numwindows>0) 
  1360.         {
  1361.             long    itemFontSize;
  1362.             short     currentSize, junk;
  1363.             Str255     temp;
  1364.             short     numOfItems;
  1365.             
  1366.             numOfItems = CountMItems(myMenus[Sizem]);
  1367.             if (numOfItems == theItem) //use picked 'other...'
  1368.             {
  1369.                 RSgetfont(screens[scrn].vs, &junk, ¤tSize);    
  1370.                 itemFontSize = SetOtherFontSize(currentSize);
  1371.             }
  1372.             else
  1373.             {
  1374.                 GetItem( myMenus[Sizem], theItem, temp);    /* JMB 2.6 -- Much safer to do it */
  1375.                 StringToNum(temp, &itemFontSize);        /*                this way! */
  1376.             }
  1377.  
  1378.             RSchangefont( screens[scrn].vs, -1, itemFontSize);
  1379.             CheckFonts();
  1380.         }
  1381.         break;
  1382.     case opspecMenu:                                            // JMB
  1383.         OpenPortSpecial(myMenus[OpSpec], theItem);                // JMB
  1384.         break;                                                    // JMB
  1385.     case prefsMenu:
  1386.         switch(theItem) {
  1387.             case prfGlobal:
  1388.                 Cenviron();
  1389.                 break;
  1390.             case prfFTP:
  1391.                 Cftp();
  1392.                 break;
  1393.             case prfSess:
  1394.                 EditConfigType(SESSIONPREFS_RESTYPE, &EditSession);
  1395.                 CheckOpSpecSubmenu();
  1396.                 break;
  1397.             case prfTerm:
  1398.                 EditConfigType(TERMINALPREFS_RESTYPE, &EditTerminal);
  1399.                 break;
  1400.             case prfFTPUser:
  1401.                 EditConfigType(FTPUSER, &EditFTPUser);
  1402.             }
  1403.         break;
  1404.     case transMenu:
  1405.         if (TelInfo->numwindows>0) {
  1406.             CheckNational(theItem-1);        // Set up the menu
  1407.             transBuffer(screens[scrn].national, theItem-1);    // Translate the scrollback buffer
  1408.             // and redraw the screen
  1409.             VSredraw(screens[scrn].vs,0,0,VSmaxwidth(screens[scrn].vs),VSgetlines(screens[scrn].vs)-1);    /* LU */
  1410.             screens[scrn].national = theItem-1;
  1411.             }
  1412.         break;
  1413.     case keyMenu:
  1414.         KeyMenu(theItem);
  1415.         break;
  1416.     case funcMenu:
  1417.         FuncMenu(theItem);
  1418.         break;
  1419. #ifdef    SPEECH
  1420.     case speechMenu:
  1421.         HandleSpeechMenu(theItem);
  1422.         break;
  1423. #endif    /* SPEECH */
  1424.     default:
  1425.         break;
  1426.     
  1427.     }
  1428.     HiliteMenu(0);
  1429.   } /* HandleMenuCommand */
  1430.  
  1431. //    Take the user's new translation choice and make sure the proper tables exist to do 
  1432. //        the translations.  If there is a problem, return the default translation as the chouce.
  1433. void    CheckNational(short choice)
  1434. {
  1435.     short i;
  1436.             
  1437.     for(i=1; i<=(nNational+1);i++)
  1438.         if ((choice+1) == i)                    /* Check the Current NatLang */
  1439.             CheckItem( myMenus[National], i, TRUE);
  1440.         else
  1441.             CheckItem( myMenus[National], i, FALSE);
  1442.  
  1443. }
  1444.  
  1445. /*
  1446.  *    extractmenu - remove a connection from the menu.
  1447.  */
  1448.  
  1449. void extractmenu(short screen)
  1450. {
  1451.     DelMenuItem(myMenus[Conn], screen + FIRST_CNXN_ITEM);
  1452.     AdjustMenus();
  1453. }
  1454.  
  1455. /*
  1456.  *    addinmenu - add a connection's name to the menu in position pnum. (name is
  1457.  *        an str255 pointed at by temps).
  1458.  */
  1459.  
  1460. void addinmenu( short screen, Str255 temps, char mark)
  1461. {
  1462.     InsMenuItem(myMenus[Conn], "\pDoh", (screen-1) + FIRST_CNXN_ITEM);
  1463.     SetItem(myMenus[Conn], screen + FIRST_CNXN_ITEM, temps);        // Avoid metas
  1464.     SetItemMark( myMenus[Conn], screen + FIRST_CNXN_ITEM, mark);
  1465.     AdjustMenus();
  1466. }
  1467.  
  1468. /*    Set the item mark for <scrn> to opening connection */
  1469. void SetMenuMarkToOpeningForAGivenScreen( short scrn)
  1470. {
  1471.     unsigned char c=0xa5;
  1472.  
  1473.     SetItemMark( myMenus[Conn], scrn + FIRST_CNXN_ITEM, c );
  1474. }
  1475.  
  1476. /*    Set the item mark for <scrn> to opened connection */
  1477. void SetMenuMarkToLiveForAGivenScreen( short scrn)
  1478. {
  1479.     SetItemMark( myMenus[Conn], scrn + FIRST_CNXN_ITEM, noMark);
  1480.     AdjustMenus();
  1481. }
  1482.  
  1483. void DoTheMenuChecks(void)
  1484. {
  1485.     short    active;
  1486.     short    windownum;
  1487.  
  1488.     if (TelInfo->numwindows>0)
  1489.         {
  1490.         EnableItem( myMenus[Conn],0);
  1491.         if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  1492.             EnableItem(myMenus[Keypad], 0);            /* Baylor */
  1493.             EnableItem(myMenus[Function], 0);        /* Baylor */
  1494.             }
  1495.         DrawMenuBar();
  1496.         }
  1497.  
  1498.     else 
  1499.         {
  1500.         DisableItem(myMenus[Conn],0);
  1501.         if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  1502.             DisableItem(myMenus[Keypad], 0);        /* Baylor */
  1503.             DisableItem(myMenus[Function], 0);        /* Baylor */
  1504.             }
  1505.         DrawMenuBar();
  1506.         }
  1507.  
  1508.     active =0;
  1509.     
  1510.     for (windownum=0;windownum<TelInfo->numwindows;windownum++)
  1511.         if (screens[windownum].active == CNXN_ACTIVE) active++;
  1512.         
  1513.     if (active<2)    
  1514.         DisableItem(myMenus[Conn],COnext);
  1515.     else EnableItem(myMenus[Conn],COnext);
  1516.  
  1517.     if (!active)
  1518.         {
  1519.         DisableItem(myMenus[Edit],EDpaste);
  1520.         DisableItem(myMenus[Emul],0);
  1521.         DrawMenuBar();
  1522.         }
  1523.     else 
  1524.         {
  1525.         EnableItem(myMenus[Edit],EDpaste);
  1526.         EnableItem( myMenus[Emul],0);
  1527.         DrawMenuBar();
  1528.         }
  1529. }
  1530.  
  1531.  
  1532.  
  1533. /*--------------------------------------------------------------------------*/
  1534. /* SetupMenusForSelection                                                    */
  1535. /* If there is a selection on screen, then let the user copy and print.        */
  1536. /* If not, then, oh well....just disable the menus and forget about it        */
  1537. /* ...and to think that this good stuff USED to be in rsmac.c.                 */
  1538. /* This is called from RSselect after the user clicks in the window, and     */
  1539. /* was moved here for modularity    - SMB                                    */
  1540. /*--------------------------------------------------------------------------*/
  1541. void SetMenusForSelection (short selected)                    /* NCSA: SB */    
  1542. {                                                            /* NCSA: SB */
  1543.     if (!selected)                                            /* NCSA: SB */
  1544.         {                                                    /* NCSA: SB */
  1545.         DisableItem(myMenus[Fil],FLprint);                    /* NCSA: SB */
  1546.         DisableItem(myMenus[Edit],EDcopy);                    /* NCSA: SB */
  1547.         DisableItem(myMenus[Edit],EDcopyt);                    /* NCSA: SB */
  1548.         }                                                    /* NCSA: SB */
  1549.     else                                                     /* NCSA: SB */
  1550.         {                                                    /* NCSA: SB */
  1551.         EnableItem(myMenus[Fil],FLprint);                    /* NCSA: SB */
  1552.         EnableItem(myMenus[Edit],EDcopy);                    /* NCSA: SB */
  1553.         EnableItem(myMenus[Edit],EDcopyt);                    /* NCSA: SB */
  1554.         }                                                    /* NCSA: SB */
  1555.         
  1556.     AdjustSpeechMenu(selected);
  1557. }                                                            /* NCSA: SB */
  1558.  
  1559.  
  1560. long SetOtherFontSize(short currentSize)
  1561. {
  1562.     DialogPtr    dtemp;
  1563.     Str255 currentSizeStr, newSizeStr;
  1564.     long newSize;
  1565.     Boolean GoodValue;
  1566.     short ditem;
  1567.     
  1568.     dtemp=GetNewMyDialog( OtherFontDLOG, NULL, kInFront, (void *)ThirdCenterDialog); 
  1569.     InitCursor();
  1570.  
  1571.     GoodValue = 0;
  1572.     
  1573.     while (!GoodValue)
  1574.     {
  1575.         GoodValue = TRUE;
  1576.         NumToString((long) currentSize, currentSizeStr);
  1577.         SetTEText(dtemp, FontSizeTE, currentSizeStr);
  1578.     
  1579.         ditem = 0;
  1580.         while(ditem != DLOGOk && ditem != DLOGCancel)
  1581.             ModalDialog(DLOGwOK_CancelUPP, &ditem);
  1582.     
  1583.         if (ditem == DLOGCancel) {
  1584.             DisposeDialog( dtemp);
  1585.             return currentSize;
  1586.         }
  1587.     
  1588.         GetTEText(dtemp, FontSizeTE, newSizeStr);
  1589.         StringToNum(newSizeStr, &newSize);
  1590.     
  1591.         if (newSize < 9)
  1592.             GoodValue = FALSE;
  1593.         
  1594.         if (!GoodValue) SysBeep(4);
  1595.     }
  1596.     DisposeDialog( dtemp);
  1597.     
  1598.     return (newSize);
  1599. }
  1600. /*----------------------------------------------------------------------*/
  1601. /* NCSA: SB - SetColumnWidth                                            */
  1602. /*    Allow the user to FINALLY pick how many columns he wants on the     */
  1603. /*    screen.  Set up a dialog box to pick the # of columns, and then        */
  1604. /*    size-up the Telnet screen accordingly.  NOTE: The user still needs    */
  1605. /*     to do a "resize", unless he is using NAWS                            */
  1606. /*----------------------------------------------------------------------*/
  1607. void SetScreenDimensions(short scrn)
  1608. {
  1609.     DialogPtr    dtemp;
  1610.     Str255        ColumnsSTR, LinesSTR;
  1611.     long        columns, lines;
  1612.     short        ditem, notgood;
  1613.     
  1614.     dtemp=GetNewMyDialog( SizeDLOG, NULL, kInFront, (void *)ThirdCenterDialog); 
  1615.     
  1616.     SetCursor(theCursors[normcurs]);
  1617.  
  1618.     notgood = 1;
  1619.     lines = VSgetlines(screens[scrn].vs);
  1620.     columns = VSgetcols(screens[scrn].vs) + 1;
  1621.     
  1622.     while (notgood) {
  1623.         notgood = 0;                                /* Default to good */
  1624.         NumToString(columns, ColumnsSTR);
  1625.         NumToString(lines, LinesSTR);
  1626.         SetTEText(dtemp, ColumnsNumber, ColumnsSTR);
  1627.         SetTEText(dtemp, LinesNumber, LinesSTR);
  1628.         SelIText( dtemp, ColumnsNumber, 0, 32767);
  1629.     
  1630.         ditem = 3;
  1631.         while(ditem>2)
  1632.             ModalDialog(DLOGwOK_CancelUPP, &ditem);
  1633.     
  1634.         if (ditem == DLOGCancel) {
  1635.             DisposeDialog( dtemp);
  1636.             return;
  1637.             }
  1638.         
  1639.         GetTEText(dtemp, ColumnsNumber, ColumnsSTR);
  1640.         StringToNum(ColumnsSTR, &columns);
  1641.         GetTEText(dtemp, LinesNumber, LinesSTR);
  1642.         StringToNum(LinesSTR, &lines);
  1643.         
  1644.         if (columns < 10) {
  1645.             columns = 10;
  1646.             notgood = 1;
  1647.             }
  1648.         else if (columns > 132) {
  1649.             columns = 132;
  1650.             notgood = 1;
  1651.             }
  1652.  
  1653.         if (lines < 10) {
  1654.             lines = 10;
  1655.             notgood = 1;
  1656.             }
  1657.         else if (lines > 200) {
  1658.             lines = 200;
  1659.             notgood = 1;
  1660.             }
  1661.         
  1662.         if (notgood) SysBeep(4);
  1663.     }
  1664.     
  1665.     DisposeDialog( dtemp);
  1666.     if (VSsetlines( screens[scrn].vs, lines) < 0) 
  1667.         OutOfMemory(-4);
  1668.     else
  1669.     {
  1670.         RScalcwsize( screens[scrn].vs, columns);
  1671.         if (screens[scrn].naws)
  1672.             SendNAWSinfo(&screens[scrn], (short)columns, (short)lines);
  1673.      }
  1674.     updateCursor(1);
  1675. }
  1676.  
  1677. void    ChangeWindowName(WindowPtr    theWindow)
  1678. {
  1679.     DialogPtr    dptr;
  1680.     short        itemHit;
  1681.     Str255        theName;
  1682.  
  1683.     if( theWindow != NULL) {
  1684.         InitCursor();
  1685.         dptr = GetNewMySmallDialog(WinTitlDLOG, NULL, kInFront, (void *)ThirdCenterDialog );
  1686.  
  1687.         GetWTitle(theWindow, theName); 
  1688.         SetTEText( dptr, kWinNameTE, theName);
  1689.         SelIText( dptr, kWinNameTE, 0, 250 );
  1690.  
  1691.         itemHit = 0;
  1692.         while(itemHit != DLOGOk && itemHit != DLOGCancel)
  1693.             ModalDialog(DLOGwOK_CancelUPP, &itemHit);
  1694.         
  1695.         if(itemHit == DLOGOk) {
  1696.             GetTEText(dptr, kWinNameTE, theName);
  1697.             set_new_window_name(theName, theWindow);
  1698.             }
  1699.             
  1700.         DisposDialog(dptr);
  1701.         }
  1702. }
  1703.  
  1704. void    set_new_window_name(Str255 theName, WindowPtr theWindow)
  1705. {
  1706.     short    i;
  1707.     
  1708.     if(theName[0]) {
  1709.         i = WindowPtr2ScreenIndex(theWindow);
  1710.         if (i >= 0) {
  1711.             i += FIRST_CNXN_ITEM;
  1712.             SetWTitle(theWindow, theName);
  1713.             SetItem(myMenus[Conn], i, theName);
  1714.             }
  1715.         }
  1716. }
  1717.